package md.NJavaOppo;

import android.util.Log;

import org.cocos2dx.lib.Cocos2dxHelper;
import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import md.NJavaBase.ICallbackQWEvent;
import md.NJavaBase.NJavaBase;
import md.NJavaBase.QWEvent;

//cocos creator相关接口
public class CCOppoNative {
    static String Tag="CCOppoNative";

    //初始化
    public static void go()
    {
        Log.i(Tag,"go");
        NJavaBase.getActivity().runOnUiThread( new Runnable(){
            @Override
            public void run() {
                //监听防沉迷结果
                NJavaOppo.addEventListener(NJavaOppo.EVT_VERIFIED_RESULT,new ICallbackQWEvent(){

                    @Override
                    public void reCall(QWEvent evt) {
                        Integer result =(Integer) evt.Details;
                        class MRunnable implements Runnable
                        {
                            MRunnable(int result)
                            {
                                m_result = result;
                            }

                            @Override
                            public void run() {
                                Log.i(Tag,"EVT_VERIFIED_RESULT recall");
                                String cmd = String.format("OppoDelegate.VerifiedResult(%d);",m_result);
                                Cocos2dxJavascriptJavaBridge.evalString(cmd);
                            }
                            int m_result;
                        }


                        Cocos2dxHelper.runOnGLThread(new MRunnable( result));
                    }
                });



                //监听登录验证结果
                NJavaOppo.addEventListener(NJavaOppo.EVT_LOGIN_RESULT,new ICallbackQWEvent(){

                    @Override
                    public void reCall(QWEvent evt) {
                        Integer result =(Integer) evt.Details;
                        class MRunnable implements Runnable
                        {
                            MRunnable(int result)
                            {
                                m_result = result;
                            }

                            @Override
                            public void run() {
                                Log.i(Tag,"EVT_LOGIN_RESULT recall");
                                String cmd = String.format("OppoDelegate.LoginResult(%d);",m_result);
                                Cocos2dxJavascriptJavaBridge.evalString(cmd);
                            }
                            int m_result;
                        }


                        Cocos2dxHelper.runOnGLThread(new MRunnable( result));
                    }
                });
            }
        } );
    }


    //退出游戏
    public static void exitGame()
    {
        Log.i(Tag,"exitGame");
        NJavaBase.getActivity().runOnUiThread( new Runnable(){
            @Override
            public void run() {
                NJavaOppo.exitGame();
            }
        } );
    }

    //跳转超休闲专区
    public static void jumpLeisureSubject()
    {
        Log.i(Tag,"jumpLeisureSubject");
        NJavaBase.getActivity().runOnUiThread( new Runnable(){
            @Override
            public void run() {
                NJavaOppo.jumpLeisureSubject();
            }
        } );
    }

    //获取防沉迷相关信息
    public static void getVerifiedInfo()
    {
        Log.i(Tag,"getVerifiedInfo");
        NJavaBase.getActivity().runOnUiThread( new Runnable(){
            @Override
            public void run() {
                NJavaOppo.getVerifiedInfo();
            }
        } );
    }

    //发起登录请求
    public static void login()
    {
        Log.i(Tag,"login");
        NJavaBase.getActivity().runOnUiThread( new Runnable(){
            @Override
            public void run() {
                NJavaOppo.login();
            }
        } );
    }
}
